import { type IDomEditor, IButtonMenu } from "@wangeditor/editor";
import { constant, AttachmentElement } from "../constant";
class MyButtonMenu implements IButtonMenu {
  title: string = constant.title;
  tag: string = constant.tag;
  getValue(editor: IDomEditor): string {
    const attachmentElem = editor.getSelectionText() || null;
    if (attachmentElem == null) return "";
    return attachmentElem;
  }
  isActive(editor: IDomEditor): boolean {
    return false;
  }
  isDisabled(editor: IDomEditor): boolean {
    return false;
  }
  exec(editor: IDomEditor, value: string | boolean) {
    if (this.isDisabled(editor)) return;
    const attachmentElem: AttachmentElement = {
      type: constant.type as AttachmentElement["type"],
      value: value as string,
      children: [{ text: "" }]
    };
    editor.insertNode(attachmentElem);
  }
}
const menu1Conf = {
  key: constant.key,
  factory() {
    return new MyButtonMenu();
  }
};
export default menu1Conf;
